package com.huixue.server.basic;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;

import javax.servlet.ServletInputStream;

public class HttpUtil {
	/**
	 * 将客户端请求的Servlet输入流转换成字符串
	 * 
	 * @param servletInputStream
	 * @return String
	 */
	public String ServletInputStreamToString(
			ServletInputStream servletInputStream) {

		BufferedReader br = null;
		StringBuffer sb = null; // 客户端向服务端请求的内容
		String temp = null; // 客户端临时读取内容

		try {
			br = new BufferedReader(new InputStreamReader(servletInputStream,
					"utf-8")); // 读取客户端请求数据
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}
		try {

			sb = new StringBuffer();
			while ((temp = br.readLine()) != null) {
				sb.append(temp);
			}
			br.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return sb.toString(); // 客户端请求内容
	}
}
